package be.rubengerits.android.car.dashboard.pager;

import java.util.List;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;
import be.rubengerits.android.car.dashboard.utils.ResourceUtils;

public class HomeCollectionPagerAdapter extends FragmentStatePagerAdapter {

	private final int mDefaultHome = 0;

	private final List<String> mLayoutsId;

	public HomeCollectionPagerAdapter(FragmentManager fm) {
		super(fm);

		try {
			mLayoutsId = ResourceUtils.getViewPagerLayouts();
		} catch (Exception e) {
			throw new RuntimeException("viewpager.xml configuration error", e);
		}
	}
	@Override
	public Fragment getItem(int item) {
		Fragment fragment = null;
		try {
			fragment = Fragment.class.cast(Class.forName(mLayoutsId.get(item)).newInstance());
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
		}
		return fragment;
	}

	@Override
	public int getCount() {
		return mLayoutsId.size();
	}

	public int getDefaultHome() {
		return mDefaultHome;
	}

}
